/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import {Form, Input, Radio, Select, Switch, TreeSelect} from 'antd';
import {connect} from 'dva';
const TreeNode = TreeSelect.TreeNode;
const FormItem = Form.Item;
const RadioGroup = Radio.Group;
const Option = Select.Option;
const {SHOW_PARENT} = TreeSelect;
@connect(({roles}) => ({
  roles
}))
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      showCustom: false
    };
  }

  componentDidMount() {
    const {dispatch} = this.props;
    dispatch({
      type: 'Roles/fetch'
    })
  }

  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 7},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };

    const {getFieldDecorator} = this.props.form;
    return (
      <div>
        <Form onSubmit={this.handleSubmit}>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               用户名
            </span>
            )}
          >
            {getFieldDecorator('username', {
              initialValue: this.props.editRecord ? this.props.editRecord.username : '',
              rules: [{required: true}],
            })(
              <Input disabled={ this.props.editRecord ? true : false}/>
            )}
          </FormItem>

          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
              角色
            </span>
            )}>
            {getFieldDecorator('role_id', {
              initialValue: this.props.editRecord ? {
                key: this.props.editRecord.role_id,
                label: this.props.editRecord.role_display_name
              } : {key: '', label: ''},
              rules: [{required: true}],
            })(
              <Select labelInValue={true}>
                { this.props.staffs.data.map((item, key) => {
                  return (
                    <Option key={item.id} disabled={item.status === -1 ? true : false}
                            value={item.id.toString()}>{item.name}</Option>
                  )
                }) }
              </Select>
            )}
          </FormItem>
        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


